﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 渐变
{
    public partial class PerCenterForm : Form
    {
        public PerCenterForm()
        {
            InitializeComponent();
        }

        private void PerCenterForm_Load(object sender, EventArgs e)
        {
            this.Dock = DockStyle.Fill;
           /* Admin admin = new Admin();
            admin = (Admin)this.Tag;*/
        }
        public void clear()
        {
            txtOldPwd.Text = "";
            txtNewPwd.Text = "";
            txtNewPwd2.Text = "";
        }
        public string Value { get; set; }
        public string NameValue { get; set; }
        /*修改密码*/
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if(label1.ForeColor == System.Drawing.Color.Green && label2.ForeColor == System.Drawing.Color.Green)
            {
                //可以修改
                string sql = "update Admin set superPassword=@newpwd where superName = @name";
                SqlParameter[] ps =
                {
                    new SqlParameter("@newpwd",txtNewPwd.Text),
                    new SqlParameter("@name",this.NameValue)
                    };
                int res = DBHelper.ExecuteNonQuery(sql, ps);
                if (res > 0)
                {
                    this.ShowSuccessTip("修改成功");
                    clear();
                }
                else
                {
                    this.ShowErrorTip("修改失败");
                    clear();
                }
            }
            else
            {
                if(label1.ForeColor == System.Drawing.Color.Red)
                {
                    this.ShowErrorTip("原密码不正确！");
                }
                if(label2.ForeColor == System.Drawing.Color.Red)
                {
                    this.ShowErrorTip("两次密码不一致！");
                }
               
            }
        
           
        }

        private void txtOldPwd_KeyUp(object sender, KeyEventArgs e)
        {
            if (this.Value == txtOldPwd.Text)
            {
                label1.Text = "密码输入正确";
                label1.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                //原密码输入不正确
                label1.Text = "原密码输入不正确";
                label1.ForeColor = System.Drawing.Color.Red;

            }
        }

        private void txtNewPwd2_KeyUp(object sender, KeyEventArgs e)
        {
            //比较新输入的两次密码
            if (txtNewPwd.Text == txtNewPwd2.Text)
            {
                label2.Text = "两次密码输入一致!";
                label2.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                //两次密码输入不一致
                label2.Text = "两次密码输入不一致!";
                label2.ForeColor = System.Drawing.Color.Red;
            }
        }
    }
}
